package com.github.h4de5ing.kmp
import java.io.File
import java.io.FileInputStream
import java.util.*

class PUtils {
    companion object {
        private var pUtils: PUtils? = PUtils()
        val instance: PUtils?
            get() {
                if (pUtils == null) pUtils = PUtils()
                return pUtils
            }
    }

    private val properties: Properties = Properties()
    fun load(fileName: String): PUtils? {
        val file = File(System.getProperty("user.dir") + File.separator + fileName)
        val `in` = (if (file.exists()) FileInputStream(file)
        else PUtils::class.java.classLoader.getResourceAsStream(fileName))
        try {
            properties.load(`in`)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return pUtils
    }

    fun get(key: String): String? {
        return properties.getProperty(key)
    }
}